package com.yp.studentsys.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {
    private int code;//设置响应状态 1成功 0失败
    private String mag;//响应信息
    private T data;//响应的数据
    /*设置通用的返回方法   四种常见的成功的响应方法*/
    public static ResponseResult createSuccess(){
                                        //1只要成功的代码         ,   默认的成功数据
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getComment(),null);
    }


    public static <T> ResponseResult<T> createSuccess(T data){
                                                              //2只要成功的数据
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getComment(),data);
    }

    public static  ResponseResult createSuccess(String msg){
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),msg,null);
    }

    public static <T> ResponseResult<T> createSuccess(String msg,T data){
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),msg,data);
    }

    /*失败响应方法*/
    public static ResponseResult createFail(){
        return new ResponseResult(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getComment(),null);
    }

    public static  <T> ResponseResult createFail(T data){
        return new ResponseResult(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getComment(),data);
    }


    public static  ResponseResult  createFail(String msg){
                                                    //自定义成功数据 msg
        return new ResponseResult(ResponseCode.FAIL.getCode(),msg,null);
    }

                                               //数据跟信息统一返回
    public static <T> ResponseResult<T> createFail(String msg, T data){
        return new ResponseResult(ResponseCode.FAIL.getCode(),msg,data);
    }

    /* 通用自定义参数方法 */
    public static <T> ResponseResult<T> createResponse(int code,String msg,T data){
        return new ResponseResult(code,msg,data);
    }

}
